package nancal.mp.db.mysql.table

import java.io.*
import nbcp.base.db.*
import nbcp.base.comm.*
import nbcp.base.extend.*
import nbcp.base.enums.*
import nbcp.base.utils.*
import nbcp.myoql.db.*
import nbcp.myoql.annotation.*
import nbcp.myoql.db.sql.*
import nbcp.myoql.db.comm.*
import nbcp.myoql.db.enums.*
import nbcp.myoql.db.sql.base.*
import nbcp.myoql.db.sql.enums.*
import nbcp.myoql.db.sql.define.*
import nbcp.myoql.db.sql.component.*
import org.springframework.stereotype.*



@Component("sql.system")
@MetaDataGroup(DatabaseEnum.Rdb, "system")
class SystemGroup: IDataGroup {
    override fun getEntities(): Set<BaseMetaData<out Any>> = setOf(s_login_user,s_user)

    /**
     * 用户登录信息
     */
    val s_login_user get() = s_login_user_table();

    /**
     * 用户
     */
    val s_user get() = s_user_table();


    /**
     * 用户登录信息
     */
    @nbcp.base.db.annotation.Cn(value = """用户登录信息""")
    @nbcp.myoql.db.sql.annotation.AutoIdColumn()
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    @nbcp.base.db.annotation.DbEntityIndexes(value = arrayOf(nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true), nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""loginName"""), unique = true)))
    open class s_login_user_table(tableName: String = ""):
        SqlBaseMetaTable<nancal.mp.db.mysql.entity.s_login_user>(nancal.mp.db.mysql.entity.s_login_user::class.java, tableName) {
        val userId = SqlColumnName(DbType.STRING, tableName,"user_id", "userId")
        val mobile = SqlColumnName(DbType.STRING, tableName,"mobile", "mobile")
        val loginName = SqlColumnName(DbType.STRING, tableName,"login_name", "loginName")
        val email = SqlColumnName(DbType.STRING, tableName,"email", "email")
        val password = SqlColumnName(DbType.STRING, tableName,"password", "password")
        val lastLoginAt = SqlColumnName(DbType.DATE_TIME, tableName,"last_login_at", "lastLoginAt")
        val errorCount = SqlColumnName(DbType.INT, tableName,"error_count", "errorCount")
        val isLocked = SqlColumnName(DbType.BOOLEAN, tableName,"is_locked", "isLocked")
        val lockedRemark = SqlColumnName(DbType.STRING, tableName,"locked_remark", "lockedRemark")
        val createAt = SqlColumnName(DbType.DATE_TIME, tableName,"create_at", "createAt")
        val updateAt = SqlColumnName(DbType.DATE_TIME, tableName,"update_at", "updateAt")
        val id = SqlColumnName(DbType.STRING, tableName,"id", "id")

        override fun getAutoIncrementKey(): String { return ""}
        override fun getUks(): Array<Array<String>>{ return arrayOf( arrayOf("id") , arrayOf("loginName")  )}
        override fun getFks(): Array<FkDefine>{ return arrayOf()}


        fun queryById (id: String): SqlQueryClip<s_login_user_table, nancal.mp.db.mysql.entity.s_login_user> {
            return this.query().where { it.id sqlEquals id }
        }


        fun deleteById (id: String): SqlDeleteClip<s_login_user_table> {
            return this.delete().where { it.id sqlEquals id }
        }

        fun updateById (id: String): SqlUpdateClip<s_login_user_table> {
            return this.update().where { it.id sqlEquals id }
        }


        fun queryByLoginName (loginName: String): SqlQueryClip<s_login_user_table, nancal.mp.db.mysql.entity.s_login_user> {
            return this.query().where { it.loginName sqlEquals loginName }
        }


        fun deleteByLoginName (loginName: String): SqlDeleteClip<s_login_user_table> {
            return this.delete().where { it.loginName sqlEquals loginName }
        }

        fun updateByLoginName (loginName: String): SqlUpdateClip<s_login_user_table> {
            return this.update().where { it.loginName sqlEquals loginName }
        }

    }
    /**
     * 用户
     */
    @nbcp.base.db.annotation.Cn(value = """用户""")
    @nbcp.myoql.db.sql.annotation.AutoIdColumn()
    @nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""id"""), unique = true)
    @nbcp.base.db.annotation.DbEntityIndexes(value = arrayOf(nbcp.base.db.annotation.DbEntityIndex(value = arrayOf("""loginName"""), unique = true)))
    open class s_user_table(tableName: String = ""):
        SqlBaseMetaTable<nancal.mp.db.mysql.entity.s_user>(nancal.mp.db.mysql.entity.s_user::class.java, tableName) {
        val name = SqlColumnName(DbType.STRING, tableName,"name", "name")
        val loginName = SqlColumnName(DbType.STRING, tableName,"login_name", "loginName")
        val code = SqlColumnName(DbType.STRING, tableName,"code", "code")
        val mobile = SqlColumnName(DbType.STRING, tableName,"mobile", "mobile")
        val isAdmin = SqlColumnName(DbType.BOOLEAN, tableName,"is_admin", "isAdmin")
        val isDeleted = SqlColumnName(DbType.BOOLEAN, tableName,"is_deleted", "isDeleted")
        val createAt = SqlColumnName(DbType.DATE_TIME, tableName,"create_at", "createAt")
        val updateAt = SqlColumnName(DbType.DATE_TIME, tableName,"update_at", "updateAt")
        val id = SqlColumnName(DbType.STRING, tableName,"id", "id")

        override fun getAutoIncrementKey(): String { return ""}
        override fun getUks(): Array<Array<String>>{ return arrayOf( arrayOf("loginName") , arrayOf("id")  )}
        override fun getFks(): Array<FkDefine>{ return arrayOf()}


        fun queryByLoginName (loginName: String): SqlQueryClip<s_user_table, nancal.mp.db.mysql.entity.s_user> {
            return this.query().where { it.loginName sqlEquals loginName }
        }


        fun deleteByLoginName (loginName: String): SqlDeleteClip<s_user_table> {
            return this.delete().where { it.loginName sqlEquals loginName }
        }

        fun updateByLoginName (loginName: String): SqlUpdateClip<s_user_table> {
            return this.update().where { it.loginName sqlEquals loginName }
        }


        fun queryById (id: String): SqlQueryClip<s_user_table, nancal.mp.db.mysql.entity.s_user> {
            return this.query().where { it.id sqlEquals id }
        }


        fun deleteById (id: String): SqlDeleteClip<s_user_table> {
            return this.delete().where { it.id sqlEquals id }
        }

        fun updateById (id: String): SqlUpdateClip<s_user_table> {
            return this.update().where { it.id sqlEquals id }
        }

    }
}

